package com.clazz;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;

public class JavaSsistDemo {

	public static void main(String[] args) throws NotFoundException, CannotCompileException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, IOException {
		Base b = new Base();
		System.out.println(b);
		ClassPool pool = ClassPool.getDefault();
		CtClass clazz = pool.get("com.clazz.Base");
		CtMethod method = clazz.getDeclaredMethod("process");
		
		method.insertBefore("System.out.println(\"start...\");");
		method.insertAfter("System.out.println(\"End...\");");
		 clazz.writeFile("E:\\JAVA\\project\\test\\target\\classes\\");
		Base newInstance =(Base) clazz.toClass().getDeclaredConstructor().newInstance();
		newInstance.process();
	}
}
